exports.main = async (context) => {
    const cloud = context.cloud;
  const collectionName = 'pfMkLooks';
  const looks = context.data.looks;

  try {
    const collection = cloud.db.collection(collectionName);
    const deletedCount = await clear(collection);
    const insertedIds = await collection.insertMany(looks);

    return {
      success: true,
      result: insertedIds
    }
  } catch (error) {
    return {
      success: false,
      error
    };
  }
};

function clear(collection) {
  return collection.deleteMany({
    _id: { $type : 'string' }
  });
}